package cn.study.luckyinfrastructure.convertor;

import cn.study.luckydomain.User.Password;
import cn.study.luckydomain.User.UserEntity;
import cn.study.luckydomain.User.UserName;
import cn.study.luckyinfrastructure.gateway.iml.dataObject.UserDB;

public class UserConvertor {
    public static UserDB toUserDB(UserEntity userEntity) {
        UserDB userDB = new UserDB();
        userDB.setId(userEntity.getId());
        userDB.setName(userEntity.getName());
        userDB.setPhone(userEntity.getPhone());
        userDB.setUsername(userEntity.getUsername().getUserName());
        userDB.setPassword(userEntity.getPassword().getEncryptionPassword().getPassword());
        userDB.setCreateTime(userEntity.getCreateTime());
        userDB.setCreator("小三");
        userDB.setUpdateTime(userEntity.getUpdateTime());
        userDB.setUpdater("小三");
        return userDB;
    }
    public static UserEntity toEntity(UserDB userDB){
        UserEntity userEntity = new UserEntity();
        userEntity.setId(userDB.getId());
        userEntity.setPhone(userDB.getPhone());
        userEntity.setName(userDB.getName());
        userEntity.setUsername(new UserName(userDB.getUsername()));
        userEntity.setCreateTime(userDB.getCreateTime());
        userEntity.setUpdateTime(userDB.getUpdateTime());
      Password p1=new Password();
      p1.getEncryptionPassword().setPassword(userDB.getPassword());
        userEntity.setPassword(p1);
        return userEntity;
    }
}
